﻿@model ProductIntroduction.Models.Config
           
@{
    ViewBag.Title = "Tạo cấu hình trang web";
}

<script src="../../../../Scripts/ajaxfileupload.js" type="text/javascript"></script>
<script type="text/javascript">
    function ajaxFileUpload() {
        //starting setting some animation when the ajax starts and completes
        $("#loading")
            .ajaxStart(function() {
                //$(this).show();
            }).ajaxComplete(function() {
                //$(this).hide();
            });

        /*
        prepareing ajax file upload
        url: the url of script file handling the uploaded files
        fileElementId: the file type of input element id and it will be the index of  $_FILES Array()
        dataType: it support json, xml
        secureuri:use secure protocol
        success: call back function when the ajax complete
        error: callback function when the ajax failed
            
        */
            $.ajaxFileUpload(
            {
                url: '/Admin/Config/Upload',
                secureuri: false,
                fileElementId: 'fileToUpload',
                dataType: 'json',
                success: function (data, status) {
                    $("#divBanner").html('<img src="' + data.FilePath + '" title="Banner" alt="Banner" />');
                },
                error: function (data, status, e) {

                }
            }
        );

        //return false;
    }
    
    $(document).ready(function() {
        $("#btnUpload").on('click', function() {
            ajaxFileUpload();
        });
    });
</script>

<h2>Tạo cấu hình trang web</h2>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Config</legend>

        <div class="editor-label">Tiêu đề trang web</div>
        <div class="editor-field">
            @Html.EditorFor(model => model.WebsiteTitle)
            @Html.ValidationMessageFor(model => model.WebsiteTitle)
        </div>

        <div class="editor-label">Tên trang web</div>
        <div class="editor-field">
            @Html.EditorFor(model => model.WebsiteName)
            @Html.ValidationMessageFor(model => model.WebsiteName)
        </div>

        <div class="editor-label">Slogan trang web</div>
        <div class="editor-field">
            @Html.EditorFor(model => model.WebsiteSlogan)
            @Html.ValidationMessageFor(model => model.WebsiteSlogan)
        </div>

        <div class="editor-label">@Html.Label("Banner")</div>
        <div class="editor-field">
            <input id="fileToUpload" type="file" size="45" name="fileToUpload" class="input">
            <input type="button" id="btnUpload" value="Upload" />
            <span data-valmsg-replace="true" data-valmsg-for="Banner" class="field-validation-valid"></span>
            <div id="divBanner"></div>
        </div>

        <div class="editor-label">@Html.Label("Footer")</div>
        <div class="editor-field">
            <textarea class="ckeditor" name="Footer">@Html.DisplayFor(model => model.Footer)</textarea>
            <span class="field-validation-valid" data-valmsg-for="Footer" data-valmsg-replace="true"></span>
        </div>

        <p>
            <input type="submit" value="Tạo cấu hình" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>
